package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * 用预编译SQL执行DMl语句
 */
public class JdbcDemo8 {
    public static void main(String[] args) {
        String sql="INSERT INTO userinfo(username,password,nickname,age) "+" VALUES(?,?,?,?)";
        try(Connection con=DBUtil.getConnection()) {
            PreparedStatement ps=con.prepareStatement(sql);
            ps.setString(1,"坤坤");
            ps.setString(2,"222");
            ps.setString(3,"菜");
            ps.setString(4,"66");
            int num=ps.executeUpdate();
            if(num>0) {
                System.out.println("成功插入");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}